package com.ctg.polling.web.dataobject;

import javax.validation.constraints.NotNull;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
public class PollResultDO implements Comparable<PollResultDO> {

	public PollResultDO (String label, int counter) {
		setLabel(label);
		setCounter(counter);
		setPercent(percent);
	}
	
	@NotNull
	private String label;
	
	@NotNull
	private Integer counter;
	
	@NotNull
	private Float percent;
	
	protected Float setPercent(Float percent) {
		return this.percent = percent;
	}
	
	@Override
	public int compareTo(PollResultDO arg0) {
		if (arg0 == null) {
			return 1;
		} 
		
		int result = 0;
		if ((result = getPercent().compareTo(arg0.getPercent())) != 0) {
			return -result; // return value is reversed because the most popular choice is displayed first.
		} else if ((result = getCounter().compareTo(arg0.getCounter())) != 0) {
			return result;
		}  else if ((result = getLabel().compareTo(arg0.getLabel())) != 0) {
			return result;
		} 
		return 0;
	}
}